
cd "~/Dropbox/Education Chile/Replication"
capture local here : dirname c(filename)
if _rc==0 cd "`here'/../../.."

global DATA "Data"
global OUT  "$DATA"

import spss using "~/Dropbox/Education Chile/Replication/Data/2006_BBDD_BicentenarioUC.sav", clear
gen encuesta = 2006
keep if p22a >= 5
keep edad p44 encuesta
rename p44 ideology

tempfile a1
save `a1'

import spss using "~/Dropbox/Education Chile/Replication/Data/2007_BBDD_BicentenarioUC.sav", clear

tab P61 // left-right
gen encuesta = 2007
keep if P71 >= 5
keep  EDAD P61 encuesta
rename EDAD edad
rename P61 ideology

tempfile a2
save `a2'

// Yes: 2007

import spss using "~/Dropbox/Education Chile/Replication/Data/2008_BBDD_BicentenarioUC.sav", clear
gen encuesta = 2008
keep if Q159 >= 5
keep Q113 Q260 encuesta
rename Q260 edad
rename Q113 ideology

tempfile a3
save `a3'

// Yes: 2008

import spss using "~/Dropbox/Education Chile/Replication/Data/2009_BBDD_BicentenarioUC.sav", clear
gen encuesta = 2009
keep if q179 >= 5
keep q139 q191 encuesta
rename q191 edad
rename q139 ideology

tempfile a4
save `a4'
// Yes: 2009

// neither 2010 nor 2011

import spss using "~/Dropbox/Education Chile/Replication/Data/2012_BBDD_BicentenarioUC.SAV", clear
keep if q226 >= 5
gen encuesta = 2012
keep q138 q237 encuesta
rename q237 edad
rename q138 ideology

tempfile a5
save `a5'

// Yes: 2012

import spss using "~/Dropbox/Education Chile/Replication/Data/2013_BBDD_BicentenarioUC.SAV", clear
keep if Q217  >= 5
gen encuesta = 2013
keep Q137 Q253 encuesta
rename Q253 edad
rename Q137 ideology

tempfile a6
save `a6'


// Yes: 2013

import spss using "~/Dropbox/Education Chile/Replication/Data/2014_BBDD_BicentenarioUC.sav", clear
keep if _v11 >= 5
gen encuesta = 2014
keep s26 edad encuesta
rename s26 ideology

tempfile a7
save `a7'


// Yes: 2014

import spss using "~/Dropbox/Education Chile/Replication/Data/2015_BBDD_BicentenarioUC.sav", clear
keep if CP1  >= 5
gen encuesta = 2015
keep S36 EDAD encuesta
rename EDAD edad
rename S36 ideology

tempfile a8
save `a8'
// Yes: 2015


import spss using "~/Dropbox/Education Chile/Replication/Data/2016_BBDD_BicentenarioUC.SAV", clear
keep if EDUCACION  >= 4
gen encuesta = 2016
keep A06 EDAD encuesta
rename EDAD edad
rename A06 ideology

tempfile a9
save `a9'
// Yes: 2016


import spss using "~/Dropbox/Education Chile/Replication/Data/2017_BBDD_BicentenarioUC.sav", clear
keep if EDUCACION   >=4
gen encuesta = 2017 
keep S11 EDAD encuesta
rename EDAD edad
rename S11 ideology

tempfile a10
save `a10'


import spss using "~/Dropbox/Education Chile/Replication/Data/2018_BBDD_BicentenarioUC.sav", clear
keep if CP01 >= 8
gen encuesta = 2018
keep S08 D08 encuesta
rename D08 edad
rename S08 ideology
tab ideology

tempfile a11
save `a11'
// Yes: 2018


import spss using "~/Dropbox/Education Chile/Replication/Data/2019_ BBDD  Bicentenario UC.sav", clear
gen encuesta = 2019
keep if cp01 >=8
keep s05 d08 encuesta
rename d08 edad
rename s05 ideology

// not 2020

forval j = 1/11 {
append using `a`j''	
}

gen dob = encuesta - edad
keep if dob >= 1950 & dob <= 1960 // 4,000 


gen treatment_dosage_coup = -6 if dob ==1949
replace treatment_dosage_coup = -5 if dob ==1950
replace treatment_dosage_coup = -4 if dob ==1951
replace treatment_dosage_coup = -3 if dob ==1952
replace treatment_dosage_coup = -2 if dob ==1953
replace treatment_dosage_coup = -1 if dob ==1954
* replace treatment_dosage_coup = 0 if dob ==1955
replace treatment_dosage_coup = 1 if dob ==1956
replace treatment_dosage_coup = 2 if dob ==1957
replace treatment_dosage_coup = 3 if dob ==1958
replace treatment_dosage_coup = 4 if dob ==1959
replace treatment_dosage_coup = 5 if dob ==1960
replace treatment_dosage_coup = 6 if dob ==1961
replace treatment_dosage_coup = 7 if dob ==1962
replace treatment_dosage_coup = 8 if dob ==1963


drop if dob == 1955

gen treat1 = 0 if treatment_dosage_coup <= -1
replace treat1 = 1 if treatment_dosage_coup >= 1

// Ideology

tab ideology encuesta, col nofreq
* Same question until 2017, drop others.

drop if encuesta == 2010


gen right = 0 
replace right = 1 if (ideology >=7 & ideology <=10) & encuesta <=2017
replace right = 1 if (ideology ==5 | ideology ==6) & encuesta  == 2018
replace right = 1 if (ideology ==4 | ideology ==5) & encuesta  == 2019

gen left = 0 
replace left = 1 if (ideology >=1 & ideology <=4) & encuesta <=2017
replace left = 1 if (ideology ==2 | ideology ==3) & encuesta == 2018
replace left = 1 if (ideology ==1 | ideology ==2) & encuesta == 2019


gen center = 0 
replace center = 1 if (ideology >=5 & ideology <=6) & encuesta <=2017
replace center = 1 if (ideology == 4) & encuesta == 2018
replace center = 1 if (ideology == 3) & encuesta == 2019

gen no_ideology = 0 
replace no_ideology = 1 if (ideology == 99)
replace no_ideology = 1 if (ideology == 11) & encuesta == 2006
replace no_ideology = 1 if (ideology >= 8) & encuesta == 2019
replace no_ideology = . if (ideology == .)


gen hard_left = 0 if ideology !=.
replace hard_left = 1 if (ideology >=1 & ideology <=2) & encuesta <=2017
replace hard_left = 1 if (ideology == 2) & encuesta == 2018
replace hard_left = 1 if (ideology == 1) & encuesta == 2019

egen cluster = group(encuesta dob)


save "~/Dropbox/Education Chile/Replication/Data/bic_all.dta", replace
